package com.jiutong.meipengdai.http.model.requests;

import com.jiutong.meipengdai.http.RetrofitHandle;
import com.jiutong.meipengdai.http.SubscribeHandler;
import com.jiutong.meipengdai.http.model.services.UserInfoService;
import com.jiutong.meipengdai.http.subscribers.ProgressSubscriber;

import java.util.HashMap;
import java.util.Map;

import rx.Observable;
import rx.Subscriber;

/**
 * Created by suxi on 2017/5/27.
 */

public class UserInfoRequest extends SubscribeHandler {

    /**
     * 注册接口
     */
    public void registed(Subscriber subscriber, Map<String, Object> fields) {

        fields.put("method", "user.register");
        handleFields(fields);
        Observable observable = RetrofitHandle.getInstance().retrofit.create(UserInfoService.class)
                .registed(fields);

        toSubscribe(observable, subscriber);
    }

    /**
     * 登录
     *
     * @param subscriber
     * @param fields
     */
    public void login(Subscriber subscriber, Map<String, Object> fields) {

        fields.put("method", "user.login");
        handleFields(fields);
        Observable observable = RetrofitHandle.getInstance().retrofit.create(UserInfoService.class)
                .login(fields);
        toSubscribe(observable, subscriber);
    }

    /**
     * 密码设置
     *
     * @param subscriber
     * @param fields
     */
    public void pwdResetByOldpwd(Subscriber subscriber, Map<String, Object> fields) {

        fields.put("method", "safe.resetPwdByPwd");
        handleFields(fields);
        Observable observable = RetrofitHandle.getInstance().retrofit.create(UserInfoService.class)
                .passwordReset(fields);
        toSubscribe(observable, subscriber);
    }

    /**
     * 获取验证码
     *
     * @param subscriber
     * @param fields
     */
    public void getAuthCode(ProgressSubscriber subscriber, HashMap<String, Object> fields) {
        fields.put("method", "user.sendCode");
        handleFields(fields);
        Observable observable = RetrofitHandle.getInstance().retrofit.create(UserInfoService.class)
                .getAuthCode(fields);
        toSubscribe(observable, subscriber);
    }

    /**
     * 身份证验证
     *
     * @param subscriber
     * @param fields
     */
    public void authIdCard(ProgressSubscriber subscriber, HashMap<String, Object> fields) {
        fields.put("method", "user.registerBase");
        fields.put("v", "2.0");
        handleFields(fields);
        Observable observable = RetrofitHandle.getInstance().retrofit.create(UserInfoService.class)
                .authIdCard(fields);
        toSubscribe(observable, subscriber);
    }

    /**
     * 换绑手机号
     *
     * @param subscriber
     * @param fields
     */
    public void changePhoneNum(ProgressSubscriber subscriber, HashMap<String, Object> fields) {
        fields.put("method", "safe.changeTelphone");
        handleFields(fields);
        Observable observable = RetrofitHandle.getInstance().retrofit.create(UserInfoService.class)
                .changePhoneNum(fields);
        toSubscribe(observable, subscriber);
    }

    /**
     * 忘记密码
     *
     * @param subscriber
     * @param fields
     */
    public void forgetPwd(ProgressSubscriber subscriber, HashMap<String, Object> fields) {
        fields.put("method", "user.findPwdByCode");
        handleFields(fields);
        Observable observable = RetrofitHandle.getInstance().retrofit.create(UserInfoService.class)
                .forgetPwd(fields);
        toSubscribe(observable, subscriber);
    }

    /**
     * 密码重置（手机验证码）
     *
     * @param subscriber
     * @param fields
     */
    public void pwdResetByCode(ProgressSubscriber subscriber, HashMap<String, Object> fields) {
        fields.put("method", "safe.resetPwdByCode");
        handleFields(fields);
        Observable observable = RetrofitHandle.getInstance().retrofit.create(UserInfoService.class)
                .pwdResetByCode(fields);
        toSubscribe(observable, subscriber);
    }

    /**
     * 邮箱验证
     *
     * @param subscriber
     * @param fields
     */
    public void emailVerify(ProgressSubscriber subscriber, HashMap<String, Object> fields) {
        fields.put("method", "safe.sendEmail");
        handleFields(fields);
        Observable observable = RetrofitHandle.getInstance().retrofit.create(UserInfoService.class)
                .emailVerify(fields);
        toSubscribe(observable, subscriber);
    }

    /**
     * 邮箱绑定
     *
     * @param subscriber
     * @param fields
     */
    public void emailBind(ProgressSubscriber subscriber, HashMap<String, Object> fields) {
        fields.put("method", "safe.bindEmail");
        handleFields(fields);
        Observable observable = RetrofitHandle.getInstance().retrofit.create(UserInfoService.class)
                .emailBind(fields);
        toSubscribe(observable, subscriber);
    }

    /**
     * 关于我们
     *
     * @param subscriber
     * @param fields
     */
    public void aboutUs(ProgressSubscriber subscriber, HashMap<String, Object> fields) {
        fields.put("method", "article.getList");
        handleFields(fields);
        Observable observable = RetrofitHandle.getInstance().retrofit.create(UserInfoService.class)
                .aboutUs(fields);
        toSubscribe(observable, subscriber);
    }

    /**
     * 校验密码
     *
     * @param subscriber
     * @param fields
     */
    public void checkPwd(ProgressSubscriber subscriber, HashMap<String, Object> fields) {
        fields.put("method", "safe.checkPassword");
        handleFields(fields);
        Observable observable = RetrofitHandle.getInstance().retrofit.create(UserInfoService.class)
                .checkPwd(fields);
        toSubscribe(observable, subscriber);
    }

    /**
     * 图片上传
     *
     * @param subscriber
     * @param fields
     */
    public void picUpload(ProgressSubscriber subscriber, HashMap<String, Object> fields) {
        fields.put("method", "upload.file");
        handleFields(fields);
        Observable observable = RetrofitHandle.getInstance().retrofit.create(UserInfoService.class)
                .picUpload(fields);
        toSubscribe(observable, subscriber);
    }

    /**
     * 发送极光registrationId
     *
     * @param subscriber
     * @param fieldMap
     */
    public void sentId(ProgressSubscriber subscriber, HashMap fieldMap) {
        fieldMap.put("method", "registrationid.add");
        handleFields(fieldMap);
        Observable observable = RetrofitHandle.getInstance().retrofit.create(UserInfoService.class)
                .sentId(fieldMap);
        toSubscribe(observable, subscriber);
    }
}
